package com.xyw.service.impl;

import java.util.List;

import com.xyw.Dao.CommodityDao;
import com.xyw.Dao.impl.CommodityDaoImpl;
import com.xyw.entity.Commodity;
import com.xyw.service.CommodityBiz;

public class CommodityBizImpl implements CommodityBiz{
CommodityDao commodity=new CommodityDaoImpl();
	@Override
	public List<Commodity> query() {
		
		return commodity.query();
	}

	
	@Override
	public List<Commodity> delete(int id) {
		if(id>0) {
			return commodity.delete(id);
		}
		return null;
	}

	

	@Override
	public Commodity queryById(int id) {
		if(id>0) {
			return commodity.queryById(id);
		}
		return null;
	}

	@Override
	public Commodity add(Commodity c) {
			if(!"".equals(c.getCommodityName())&&c.getUnitPrice()>0) {;
				return commodity.add(c);
		}
		return null;
	}


	@Override
	public Commodity update(Commodity c) {
		if(!"".equals(c.getCommodityName())&&c.getUnitPrice()>0) {
			return commodity.update(c);
		}
		return null;
	}


	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return commodity.getCount();
	}


	@Override
	public List<Commodity> getPage(int page, int size) {
		int count = getCount();
		int pageCount = count % size == 0 ? count / size : (count / size + 1);

		page = page < 1 ? 1 : page;
		page = page > pageCount ? pageCount : page;
		return commodity.getPage(page, size);
	}


	@Override
	public boolean deleteById(int id) {
		// TODO Auto-generated method stub
		return commodity.deleteById(id);
	}

}
	
	
